﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LeMigue.Scrum.Iterface.Model
{
    public class Sprint : ScrumItem, IHasTask, IHasBacklog, IHasBug, IHasIteration
    {
        public DateTime? Start { get; set; }
        public DateTime? End { get; set; }

        public string Goal { get; set; }

        public Iteration Iteration {get; set;}

        internal Lazy<IList<ItemBacklog>> _itensBacklog;

        internal Lazy<IList<Bug>> _bugs;

        internal Lazy<IList<Task>> _tasks;

        public Sprint(int id, string title)
            : base(id, title)
        {
        }


        public IList<ItemBacklog> Backlogs
        {
            get { return _itensBacklog.Value; }
        }

        public IList<Bug> Bugs
        {
            get { return _bugs.Value; }
        }
        public IList<Task> Tasks
        {
            get { return _tasks.Value; }
        }

        public void SetBacklogs(Lazy<IList<ItemBacklog>> backlogs)
        {
            _itensBacklog = backlogs;
        }

        public void SetBugs(Lazy<IList<Bug>> bugs)
        {
            _bugs = bugs;
        }

        public void SetTasks(Lazy<IList<Task>> tasks)
        {
            _tasks = tasks;
        }
        public bool Atual
        {
            get
            {
                if (Start.HasValue && End.HasValue)
                {
                    if (Start.Value.Date <= DateTime.Now.Date && End.Value.Date >= DateTime.Now.Date)
                        return true;
                }
                return false;
            }
        }


        /// <summary>
        /// Retorna se tem ou não tarefas
        /// </summary>
        public bool HasTask
        {
            get { return Tasks.Count > 0; }
        }

        /// <summary>
        /// Retorna se tem ou não bugs
        /// </summary>
        public bool HasBug
        {
            get { return Bugs.Count > 0; }
        }

        /// <summary>
        /// Retorna se tem ou não itens no backlog
        /// </summary>
        public bool HasBacklog
        {
            get { return Backlogs.Count > 0; }
        }
    }
}
